using System;
using UnityEngine;
public class mSystem
{
	
	public static void arraycopy( sbyte[] scr, int scrPos, sbyte[] dest, int destPos, int lenght)
	{
		
		Array.Copy(scr, scrPos, dest, destPos, lenght);
		
//		if ( scr == null || dest == null || destPos + lenght > dest.Length)
//			return;
//		
//		for ( int i = scrPos; i < lenght; i++)
//			dest[destPos + i - scrPos] = scr[i];
	}
	
	public static void arrayReplace( sbyte[] scr, int scrPos,ref sbyte[] dest, int destPos, int lenght)
	{
		if ( scr == null || dest == null || scrPos + lenght > scr.Length)
			return;
		
		sbyte[] temp = new sbyte[dest.Length + lenght];
		
		for ( int i = 0; i < destPos; i++)
			temp[i] = dest[i];
		
		for ( int i = destPos; i < destPos+lenght; i++)
			temp[i] = scr[scrPos + i - destPos];
		
		for ( int i = destPos+lenght; i < temp.Length; i++)
			temp[i] = dest[destPos + i - lenght];
		
	}
	
    public static long currentTimeMillis()
    {
        DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
        long current = (DateTime.UtcNow.Ticks - epoch.Ticks) / TimeSpan.TicksPerMillisecond;
        return current;
      
    }

	public static void freeData(){
		Resources.UnloadUnusedAssets();
		System.GC.Collect();			
	}
	public static sbyte[] convertToSbyte( byte[] scr)
	{
		sbyte[] data = new sbyte[scr.Length];
		for( int i = 0; i < scr.Length; i++)
			data[i] = (sbyte) scr[i];
		return data;
	}
	
	public static sbyte[] convertToSbyte( string scr)
	{
		System.Text.ASCIIEncoding  encoding = new System.Text.ASCIIEncoding();
   	 	Byte[] bytes = encoding.GetBytes(scr);
		return convertToSbyte(bytes);
	}
	
	public static byte[] convetToByte( sbyte[] scr)
	{
		byte[] temp = new byte[scr.Length];
		for(int i = 0; i < scr.Length; i++)
		{
			if ( scr[i] > 0)
				temp[i] =  (byte)scr[i];
		
			else temp[i] = (byte)(scr[i] + 256);
		}
		
		return temp;
	}
	
	public static char[] ToCharArray( sbyte[] scr)
	{
		char[] data = new char[scr.Length];
		for( int i = 0; i < scr.Length; i++)
			data[i] = (char) scr[i];
		return data;
	}
	
	
	
	
	public static int currentHour()
	{
		return System.DateTime.Now.Hour;
	}
	
	public static void println( object str)
	{
		Debug.Log(str);
	}
	
	public static void gcc()
	{
		Resources.UnloadUnusedAssets ();
		System.GC.Collect ();	
		
	}
}
